package com.emm.yixun.system.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.emm.yixun.common.utils.SMSUtil;
import com.emm.yixun.system.service.SMSMessageFacade;

@Service("SMSMessageFacade")
public class SMSMessageServiceFacadeImpl implements SMSMessageFacade {
	private static Logger logger = LoggerFactory
			.getLogger(SMSMessageServiceFacadeImpl.class);
	@Autowired
	private SMSUtil smsUtil;

	public boolean sendMobileMsg(String phoneNumber, String content) {
		try {
			logger.info("send[{}], content[{}]", phoneNumber, content);
			if (null == phoneNumber || "".equals(phoneNumber)) {
				logger.error("phoneNumber must not be null!");
				return false;
			}
			// 发送短信
			int sentResult = smsUtil.sendSMS(content, phoneNumber);

			if (sentResult == 0) {
				return true;
			} else {
				logger.error("send message fail:{}", SMSUtil.getMsg(sentResult));
				return false;
			}
		} catch (Exception e) {
			logger.error("sendMobileMsg error: ", e);
			return false;
		}
	}

	public boolean sendSMS(String content, String[] numbers) {
		logger.info("send[{}], content[{}]", numbers, content);
		if (null == numbers || numbers.length == 0) {
			logger.error("phoneNumber[] must not be null!");
			return false;
		}
		int sentResult = smsUtil.sendSMS(content, numbers);
		if (sentResult > 0) {
			return true;
		} else {
			logger.error("send message fail:{}", SMSUtil.getMsg(sentResult));
			return false;
		}
	}
}
